package com.china08.yxyapi.api.manage.stu.mystudy.homework.workreport;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.security.profile.YxyProfile;
import com.china08.yxyapi.service.manage.stu.mystudy.homework.dowork.impl.HomeworkServiceImplv01;

/**
 * 试题类作业 作业提交 2017年3月11日09:15:54
 * 
 * @author lys
 *
 */
@CrossOrigin
@RestController
public class HomeWorkReportFinishworkControllerV01 extends YxyApiBaseController {
    @Autowired
    HomeworkServiceImplv01 homeworkSrevice;

    /**
     * 学生点击提交按钮后的操作 2017年3月11日09:27:11
     * 
     * @param reqModel
     * @param request
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/api_yw/manage/stu/mystudy/homework/workreport/finishwork/v01", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public YxyApiRespModel process(@RequestBody ReqModel reqModel, HttpServletRequest request,
            HttpServletResponse response) {
        RespModel respModel = new RespModel();
        // 获取当前用户信息
        YxyProfile yxyProfile = getProfile(request, response);
        Assert.isTrue(yxyProfile != null, "用户信息异常，请重新登录！");
        homeworkSrevice.commitHomework(reqModel.studentId, reqModel.taskId, "试题");

        respModel.setMessage("作业提交成功");
        return respModel;

    }

    // 返回的对象类型
    protected class RespModel extends YxyApiRespModel {
    }

    // 请求的参数类型
    protected static class ReqModel extends YxyApiReqModel {
        // 任务ID
        public String taskId;
        // 学生ID
        public String studentId;
        // 是否自动提交作业，只有选择题的时候自动提交为true TODO
        public Boolean isZDPJ;

    }

}
